@inherits BaseFieldValueComponent<Guid?, SingleFileFieldModel>
@namespace FluentCMS.Web.Plugins.Admin.ContentTypeManagement

<FormField Label="@ContentTypeField!.Label" Cols="@Field.FormColWidth" Required="@ContentTypeField!.Required" OnChange="OnFilesChanged">

@if (FieldValue.Value == null)
{
    <Grid>
        <Button @onclick="OpenFileSelectorModal">Choose File</Button>
    </Grid>
}
else
{
    <Card>
        <CardBody>
            <Grid JustifySmall="GridJustify.Between" ItemsSmall="GridItems.Center">
                <GridItem>
                    <Typography>@FileName</Typography>
                </GridItem>
                <GridItem>
                    <Stack Justify="StackJustify.End">
                        <Button Size="ButtonSize.Small" Ghost Color="Color.Primary" Href="@FileUrl" target="_blank">
                            <Icon Name="IconName.Download" />
                        </Button>
                        <Button Size="ButtonSize.Small" Ghost Color="Color.Danger" @onclick="() => FieldValue.Value = default!">
                            <Icon Name="IconName.Delete" />
                        </Button>
                    </Stack>
                </GridItem>
            </Grid>
        </CardBody>
    </Card>
}
</FormField>

@if (FileSelectorModalOpen)
{
    <FileSelectorModal FolderId="RootFolder.Id" OnCancel="CloseFileSelectorModal" OnSubmit="OnFileSelectorSubmit"/>
}